var dependency = ['plugins/router', 'plugins/http', 'knockout'];
['bank', 'forum', 'news', 'shop'].map(function(module) {
    dependency.push('app/' + module + '/router')
});

define(dependency, function(router, http, ko) {
    var routers = [];

    // 从路由文件提取路由规则
    function getRouters(args) {
        routers = [
            { route: '', title: '首页', moduleId: 'app/home' },
        ];
        for (var i = 1, len = args.length; i < len; i++) {
            if (args[i].hasOwnProperty('__moduleId__') && /^app\/(\w+)\/router/g.test(args[i]['__moduleId__'])) {
                delete args[i]['__moduleId__'];
                console.log('赵大鹏啦');
                routers = routers.concat(args[i]);
            }
        }
    }
    getRouters(arguments);
    router.map(routers).buildNavigationModel();

    return {
        router: router,
        modules: ko.observableArray([]),
        goModule: function(module) {
            console.log(module);
            router.navigate('#' + module.Name());
        },
        goBack: function() {
            router.navigateBack();
        },
        activate: function() {
            var self = this;
            http.get('mock/app.modules.json').then(function(data) {
                data.Modules = [{
                    Title: '首页',
                    Name: ''
                }].concat(data.Modules);
                ko.mapping.fromJS(data.Modules, {}, self.modules)
            })

            // router.map(routers).buildNavigationModel();
            // router.map([{ route: 'bank', title: '银行首页', moduleId: 'app/bank/home' }]).buildNavigationModel();
            return router.activate();
        }
    }
});